<link rel="stylesheet" href="../../../lib/layui-v2.6.3/css/layui.css" media="all">
<link rel="stylesheet" href="../../../lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
<link rel="stylesheet" href="../../../css/layuimini.css?v=2.0.1" media="all">
<link rel="stylesheet" href="../../../css/themes/default.css" media="all">
<link rel="stylesheet" href="../../../css/public.css" media="all">
<div class="layuimini-main">
	<div class="layui-form layuimini-form">
		<div class="layui-form-item">
			<label class="layui-form-label required">标签名称</label>
			<div class="layui-input-block">
				<input type="text" name="tagName" lay-verify="required" lay-reqtext="标签名称不能为空" placeholder="请输入标签名称" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label required">来源分支</label>
			<div class="layui-input-block">
				<select name="orgBranchName" id="orgBranchName" lay-search lay-verify="required" lay-reqtext="来源分支不能为空">
					<option value="">请输入或选择分支</option>
				</select>
			</div>
		</div>
		<input type="hidden" name="appId" id="appId2"/>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
			</div>
		</div>
	</div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script src="../../js/common.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
			parentIndex = layer.index,
			appId = localStorage.getItem('appId_' + parent.layui.$("#userName").val());
		
		$("#appId2").val(appId);
		
		initBranch(form, $, appId);
		
        form.on('submit(saveBtn)', function(data) {
			$.ajax({
				url: '/app/tag/add',
				type: 'POST',
				dataType: "json",
				contentType: 'application/json;charset=UTF-8',
				data: JSON.stringify(data.field),
				success: function(data){
					if(data.code != "000000"){
						layer.msg(data.message, {icon: 5, shift: 6});
						return false;
					}
					
					layer.msg("保存成功", {
						icon: 1,
						time: 500,
						shade: 0.01,
						shadeClose: false
					}, function(){
						parent.layer.close(parent.layer.getFrameIndex(window.name));
						parent.layui.table.reload('currentTableId');
					});
				},
				error: function(data){
					parent.layer.close(parent.layer.getFrameIndex(window.name));
					layer.msg(data.message, {icon: 5, shift: 6});
				}
			});
            return false;
        });
    });
	
	function initBranch(form, $, appId){
		$.ajax({
			url: '/app/branch/search',
			type: 'POST',
			dataType: "json",
			contentType: 'application/json;charset=UTF-8',
			data: JSON.stringify({'appId': appId}),
			success: function(res){
				data = res.data
				var opt = '';
				for(var k in data){
					opt = opt.concat("<option value='"+ data[k].branchName +"'>"+ data[k].branchName +"</option>");
				}
				$("#orgBranchName").append(opt);
				form.render('select');
			},
			error: function(data){
				layer.msg(data.message, {icon: 5, shift: 6});
			}
		});
	}
</script>
</body>
</html>